<?php

$line = array('ACCOUNT_NUMBER', 'INST_FIRST_NAME', 'INST_LAST_NAME', 'SALUTATION', 'COMPANY_NAME', 'PO_BOX', 'LANGUAGE', 'BILL_STREET', 'BILL_HOUSE_NO', 'BILL_ZIP', 'BILL_CITY');
$csv->addRow($line);

foreach($result AS $r)
  {
    if(strpos($r['c']['inst_first_name'],'#') !== false) {
    	$r['c']['inst_first_name'] = "";
    	$r['c']['salutation'] = "";
    }
    if(strpos($r['c']['inst_last_name'],'#') !== false) {
    	$r['c']['inst_last_name'] = "";
    	$r['c']['salutation'] = "";
    }
    if(strlen($r['c']['company_name']) == 1) { $r['c']['company_name'] = ""; }
    
   
    $line = array($r['c']['account_number'], $r['c']['inst_first_name'], $r['c']['inst_last_name'], $r['c']['salutation'], trim($r['c']['company_name']), $r['c']['po_box'], $r['c']['language'], $r['c']['bill_street'], $r['c']['bill_house_no'], $r['c']['bill_zip'], $r['c']['bill_city']);
    $csv->addRow($line);
  }

$datum = date("d.m.Y");
$end = ".csv";
$title = "Export_SchmidFehr_Runid-".$runid."_".$datum.".csv";
echo $csv->render($title);
?>